/**
 * 菜单操作
 */
$(function(){
	
	$(".foodList").slideDown(1000);
	//点你
	$(".DNBtn").bind("click",function(){
		//var r = confirm("确认后就不能修改咯？");
		var thisObj = this;
		cfm("如果客服妹妹提交订单了，就不能修改咯？",function(r){
			if(r){
				var fid = $(thisObj).attr("fid");
				/*$("input[name='foodIds']").attr("checked", false);*/
				$("input[name='foodIds'][value='"+fid+"']").attr("checked", true);
				$("#foodForms").ajaxSubmit({
					dataType : 'json',
					success : function(data) {
						if (data.isSuccess == 1) {
							alt('恭喜您，点餐成功！');
							deleteRowTR(thisObj);//删除行
							flushBanlance();//刷新余额
							//window.location.href=root+"foodController/queryFoods.html";
						}else{
                            alt(data.msgInfo);
						}
					}
				});
			}
		});
	});
	//提交菜单
	$(".pldcBtn").bind("click",function(){
		var foodIds = $("input[name='foodIds']:checked");
		if(foodIds.length>0){
			cfm("如果客服妹妹提交订单了，就不能修改咯？",function(r){
				if(r){
					$("#foodForms").ajaxSubmit({
						dataType : 'json',
						success : function(data) {
							if (data.isSuccess == 1) {
								alt('恭喜您，点餐成功！',function(r){
									window.location.href=root+"foodController/queryFoods.html";
								});
							}else{
								alt(data.msgInfo);
							}
						}
					});
				}
			});
		}else{
			alt("请先选择您需要点的菜喔！");
		}
	});
	//刷新页面
	$(".flushBtn").bind("click",function(){
		location.reload();
	});
	//局部刷新余额
	function flushBanlance(){
		$.ajax({
			dataType:'json',
			url:root+"foodController/flushBanlance.html",
			success : function(data) {
				//console.info(data);
				//alert(data.model.myBanlance);
				$(".myBanlance").html(data.model.myBanlance);
			}
		});
	}
	
	//取消订单
	$(".cancelOrderBtn").bind('click',function(){
		var thisObj = this;
		var oid = $(thisObj).attr("oid");
		var fid = $(thisObj).attr("fid");
		cfm("您确认今天不吃这个菜了吗？",function(r){
			if(r){
				$.ajax({
					dataType:'json',
					url:root+"foodController/"+oid+"/"+fid+"/cancelOrderItem.html",
					success : function(data) {
						if (data.isSuccess == 1) {
							alt("已经帮您取消啦！^_^");
							deleteRowTR(thisObj);//删除行
							flushBanlance();//刷新余额
						}else{
							alt(erInfo);
						}
					}
				});
			}
		});
	});
	//提交当日的订单
	$(".submitBtn").bind('click',function(){
		cfm("您确认今天大家就吃这些菜了吗？",function(r){
			if(r){
				$.ajax({
					dataType:'json',
					url:root+"foodController/submitOrderItems.html",
					success : function(data) {
						if (data.isSuccess == 1) {
							alt("已经提交啦，等着美餐的到来吧！^_^",function(){
								window.location.reload(true);
							});
						}else{
							alt(erInfo);
						}
					}
				});
			}
		});
	});
	
});